package com.sailfish.springbootdemo.dao.db2;

import com.sailfish.springbootdemo.common.DB2TableName;
import com.sailfish.springbootdemo.pojo.db2.PcbNewTechnologyInfo;
import com.sailfish.springbootdemo.pojo.db2.PcbSonFactoryInfo;
import com.sailfish.springbootdemo.pojo.db2.PcbSpecialProcessInfo;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;

import java.util.List;

public interface PcbSpecialProcessInfoDao {

    @Results(id = "pcbSpecialProcessInfoMap", value = {
            @Result(column = "pcb_special_process_id", property = "pcbSpecialProcessId", jdbcType = JdbcType.INTEGER),
            @Result(column = "pcb_special_process_name", property = "pcbSpecialProcessName", jdbcType = JdbcType.VARCHAR),
            @Result(column = "pcb_special_process_name_en", property = "pcbSpecialProcessNameEn", jdbcType = JdbcType.VARCHAR),
            @Result(column = "version", property = "version", jdbcType = JdbcType.VARCHAR),
            @Result(column = "remark", property = "remark", jdbcType = JdbcType.VARCHAR),
            @Result(column = "change_history", property = "changeHistory", jdbcType = JdbcType.VARCHAR),
            @Result(column = "create_time", property = "createTime", jdbcType = JdbcType.DATETIMEOFFSET),
            @Result(column = "update_time", property = "updateTime", jdbcType = JdbcType.DATETIMEOFFSET),
            @Result(column = "status", property = "status", jdbcType = JdbcType.INTEGER),
            @Result(column = "sort", property = "sort", jdbcType = JdbcType.INTEGER),
            @Result(column = "create_user", property = "createUser", jdbcType = JdbcType.VARCHAR),
            @Result(column = "update_user", property = "updateUser", jdbcType = JdbcType.VARCHAR),
    })

    /*
     *查询单个
     */
    @Select("<script> " +
            "select pcb_special_process_id, pcb_special_process_name, pcb_special_process_name_en, version, remark, change_history, create_time, create_user, update_time, update_user, status, sort" +
            " from " + DB2TableName.PCB_SPECIAL_PROCESS_INFO +
            " where pcb_special_process_id = #{id}" +
            "</script>")
    PcbSpecialProcessInfo getById(@Param("id") Integer id);

    /*
     *查询指定行数据
     */
    @Select("<script> " +
            "select pcb_special_process_id, pcb_special_process_name, pcb_special_process_name_en, version, remark, change_history, create_time, create_user, update_time, update_user, status, sort" +
            " from " + DB2TableName.PCB_SPECIAL_PROCESS_INFO +
            " where 1=1 " +
            "<if test='pcbSpecialProcessName != null and pcbSpecialProcessName != \"\"'>" +
            "and ( pcb_special_process_name like concat('%',#{pcbSpecialProcessName},'%') or pcb_special_process_name_en like concat('%', #{pcbSpecialProcessNameEn},'%'))" +
            "</if>" +
            "<if test='version != null and version != \"\"' >" +
            "and version = #{version}" +
            "</if>" +
            "<if test='status != null' >" +
            "and status = #{status}" +
            "</if>" +
            " order by sort" +
            "</script>")
    @ResultMap(value = "pcbSpecialProcessInfoMap")
    List<PcbSpecialProcessInfo> getAllByLimit(@Param("pcbSpecialProcessName") String pcbSpecialProcessName,
                                              @Param("pcbSpecialProcessNameEn") String pcbSpecialProcessNameEn,
                                              @Param("version") String version, @Param("status") Integer status);

    @Select("<script> " +
            "select pcb_special_process_id, pcb_special_process_name, pcb_special_process_name_en, version, remark, change_history, create_time, create_user, update_time, update_user, status, sort" +
            " from " + DB2TableName.PCB_SPECIAL_PROCESS_INFO +
            " where 1=1 " +
            "<if test='pcbSpecialProcessName != null and pcbSpecialProcessName != \"\"'>" +
            "and pcb_special_process_name = #{pcbSpecialProcessName}" +
            "</if>" +
            "<if test='version != null and version != \"\"' >" +
            "and version = #{version}" +
            "</if>" +
            "<if test='status != null' >" +
            "and status = #{status}" +
            "</if>" +
            " order by sort" +
            "</script>")
    @ResultMap(value = "pcbSpecialProcessInfoMap")
    List<PcbSpecialProcessInfo> getAllByLimit2(@Param("pcbSpecialProcessName") String pcbSpecialProcessName,
                                               @Param("pcbSpecialProcessNameEn") String pcbSpecialProcessNameEn,
                                               @Param("version") String version, @Param("status") Integer status);

    @Insert("insert into " + DB2TableName.PCB_SPECIAL_PROCESS_INFO + "(pcb_special_process_name, pcb_special_process_name_en, version, remark, change_history, create_time, create_user, update_time, update_user, status, sort) values" +
            " (#{pcbSpecialProcessName}, #{pcbSpecialProcessNameEn}, #{version}, #{remark}, #{changeHistory}, #{createTime}, #{createUser}, #{updateTime}, #{updateUser}, #{status}, #{sort})")
    // 显式设置主键
    @Options(useGeneratedKeys = true, keyProperty = "pcbSpecialProcessId")
    Integer insert(PcbSpecialProcessInfo param);


    @Insert("<script>" +
            "insert into " + DB2TableName.PCB_SPECIAL_PROCESS_INFO + "(pcb_special_process_name, pcb_special_process_name_en, version, remark, change_history, create_time, create_user, update_time, update_user, status, sort) values" +
            "<foreach collection=\"entities\" item=\"entity\" separator=\",\">" +
            " (#{entity.pcbSpecialProcessName}, #{entity.pcbSpecialProcessNameEn}, #{entity.version}, #{entity.remark}, #{entity.changeHistory}, #{entity.createTime}, #{entity.createUser}, #{entity.updateTime}, #{entity.updateUser}, #{entity.status}, #{entity.sort})" +
            "</foreach>" +
            "</script>")
    // 显式设置主键
    @Options(useGeneratedKeys = true, keyProperty = "pcbSpecialProcessId")
    Integer insertBatch(@Param("entities") List<PcbSpecialProcessInfo> entities);

    /*
     *通过主键删除
     */
    @Delete("delete from " + DB2TableName.PCB_SPECIAL_PROCESS_INFO + " where pcb_special_process_id = #{id} ")
    Integer delete(@Param("id") Integer id);

    /*
     *通过主键修改数据
     */
    @Update("<script>" +
            "update " + DB2TableName.PCB_SPECIAL_PROCESS_INFO +
            "<set> " +
            "<if test='pcbSpecialProcessName != null and pcbSpecialProcessName != \"\"'>" +
            "pcb_special_process_name = #{pcbSpecialProcessName}," +
            "</if>" +
            "<if test='pcbSpecialProcessNameEn != null and pcbSpecialProcessNameEn != \"\"'>" +
            "pcb_special_process_name_en = #{pcbSpecialProcessNameEn}," +
            "</if>" +
            "<if test='version != null and version != \"\"'>" +
            "version = #{version}," +
            "</if>" +
            "<if test='remark != null and remark != \"\"'>" +
            "remark = #{remark}," +
            "</if>" +
            "<if test='changeHistory != null and changeHistory != \"\"'>" +
            "change_history = #{changeHistory}," +
            "</if>" +
            "<if test='createUser != null and createUser != \"\"'>" +
            "create_user = #{createUser}," +
            "</if>" +
            "<if test='createTime != null '>" +
            "create_time = #{createTime}," +
            "</if>" +
            "<if test='updateUser != null and updateUser != \"\"'>" +
            "update_user =#{updateUser}," +
            "</if>" +
            "<if test='updateTime != null '>" +
            "update_time = #{updateTime}," +
            "</if>" +
            "<if test='status != null '>" +
            "status = #{status}," +
            "</if>" +
            "<if test='sort != null '>" +
            "sort = #{sort} " +
            "</if>" +
            "</set> " +
            "where pcb_special_process_id = #{pcbSpecialProcessId}" +
            "</script>")
    Integer update(PcbSpecialProcessInfo param);

}
